<?

include "../config/constants.php";

if( $_GET[_test] ){
	$_POST[query] = "select * from `contentsmetadata_db`.`tblContent` LIMIT 0,1";
}

if( !$_POST[query] ){
	echo "ERROR";
	exit;
}


$query =  stripslashes($_POST[query]);

$mysqli = mysqli_connect("localhost", "canss", "1022", "contentsmetadata_db") or die("Could not connect: " . mysql_error());
mysqli_query($mysqli, "SET NAMES 'utf8'");
$result = mysqli_query( $mysqli, $query );

$Body = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
EOD;

$Body = $Body.file_get_contents("../config/schema_head.txt" );
while($row = mysqli_fetch_array($result)){
	$req = new HttpRequest(REV_FORMATTER_URL, HttpRequest::METH_POST);
	$req->addPostFields(array('OBJ' => serialize($row)));
	$Body = $Body.$req->send()->getBody();
}
$Body = $Body.file_get_contents("../config/schema_tail.txt" );

$req = new HttpRequest(REV_ORCHESTRATOR_URL, HttpRequest::METH_POST);
$req->addPostFields(array('XML' => $Body));
if( $_POST[_3pid] || $_POST[_chid] ) $req->addPostFields(array('RRID' => 'R'.md5($_POST[_3pid].$_POST[_chid])));
echo stripslashes($req->send()->getBody());

?>
